package com.allwees.data.analysis.stat.req;

import com.allwees.bs.core.model.stat.EStatType;
import com.allwees.bs.core.modelbase.constant.EPlatform;
import com.allwees.bs.core.modelbase.req.Req;
import com.allwees.data.analysis.stat.EStatMode;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 *
 *
 * @author yangylsky
 * @since 2020-04-14
 *
 */
@Data
@EqualsAndHashCode(callSuper=false)
@Accessors(chain = true)
public abstract class QueryStatReq extends Req implements Cloneable {
	protected EStatType statType;

	/**
	 * 值统计类型，用于百分比类型的统计，此时value=value(valueStatType)/value(baseStatType)
	 */
	protected EStatType valueStatType;

	/**
	 * 基数统计类型，用于百分比类型的统计，此时value=value(statType)/value(baseStatType)
	 */
	protected EStatType baseStatType;

	protected EPlatform platform;

	protected StatLevel level;

	protected Date dateFrom;

	protected Date dateTo;

	/**
	 * 是否同时查询上一个统计周期（用于计算increment）
	 */
	protected boolean queryPrev = true;

	protected boolean queryDetail = true;

	protected String bsKey;

	public abstract EStatMode statMode();

	@SuppressWarnings("unchecked")
	public <R extends QueryStatReq> R setStatType(EStatType statType) {
		this.statType = statType;
		return (R) this;
	}

	@SuppressWarnings("unchecked")
	public <R extends QueryStatReq> R setValueStatType(EStatType valueStatType) {
		this.valueStatType = valueStatType;
		return (R) this;
	}

	@SuppressWarnings("unchecked")
	public <R extends QueryStatReq> R setBaseStatType(EStatType baseStatType) {
		this.baseStatType = baseStatType;
		return (R) this;
	}

	public enum StatLevel {
		UV,
		PV,
		IPV
	}

	public abstract QueryStatReq _clone();

	public abstract QueryStatReq prevPeriod();

	/**
	 * 返回基于dateFrom偏移offset的Date
	 *
	 * @param offset
	 * @return
	 */
	public abstract Date offsetDateFrom(int offset);

	public abstract int interval();
}
